Link to this headingFrom Scratch

Link to this headingKernel Image

Make Kernel Image:

#Get the Git repo git clone https://github.com/torvalds/linux cd linux #Modify items make menuconfig # unselect the platforms that you dont need # Platform -> make -j8 # Show Linux Image >>> ls ./arch/x86_64/boot -al lrwxrwxrwx - generalzero 3 Apr 20:07 bzImage -> ../../x86/boot/bzImage

Link to this headingInitramfs

Create initramfs:

yay -S uboot-tools #Busybox git clone git://git.busybox.net/busybox cd busybox #Compile make config #Change Settings # Settings -> [*] Build static binary make -j8 # make install cd .. #Make initramfs file system mkdir -p initramfs/bin initramfs/sbin initramfs/etc initramfs/proc initramfs/dev initramfs/usr/bin initramfs/usr/sbin cp -a busybox/_install/* ./initramfs cd initramfs #Create init file cat > ./init << EOF mount -t proc none /proc mount -t sysfs none /sys exec /bin/sh EOF chmod +x ./init #Create CPIO image find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz cd .. mkimage -A x86_64 -O linux -T ramdisk -C gzip -d initramfs.cpio.gz initramfs.cpio.gz.uboot

There is a issue with busybox with the net kernel so lets use an older docker to compile it.

Building busybox with Docker:

sudo docker pull debian:bullseye sudo docker run -it -v `pwd`:/busybox --name busybox-builder debian:bullseye #Install dependencies apt update apt install -y build-essential wget git #Start to compile and package cd /busybox make -j$(nproc) make install CONFIG_PREFIX=/busybox/_install

Link to this headingTFTP

Setup TFTP:

mkdir -p ./tftp/recovery cp ./linux/arch/x86_64/boot/*Image* ./tftp/recovery cp ./initramfs.cpio.gz* ./tftp/recovery cd ./tftp/recovery #Make Image #mkimage -f board.its board.itb #cd .. #Setup TFTP server cat > ./compose.yml << EOF services: tftp-server: image: taskinen/tftp:latest entrypoint: in.tftpd command: -L -4 --secure --address 0.0.0.0:69 --verbosity 3 /var/tftpboot ports: - "0.0.0.0:69:69/udp" volumes: - ./recovery:/var/tftpboot:ro restart: unless-stopped EOF sudo docker-compose down && sudo docker-compose pull && sudo docker-compose up --remove-orphans -d

Link to this headingBuild Debian image

Create Bootable image:

#Install if missing commands yay -S qemu-tools qemu-img #Make Image qemu-img create sdcard.img 4G sudo parted --script sdcard.img \ mktable gpt mkpart primary ext4 1M 500M mkpart primary ext4 500M 100% set 1 boot on #Mount the device so we can work on it sudo losetup --show -f sdcard.img sudo mkfs.ext4 /dev/mapper/loop0p1 sudo mkfs.ext4 /dev/mapper/loop0p2 sudo mount /dev/mapper/loop0p2 /mnt/sdcard #Setup debian sudo debootstrap --arch=x86_64 --foreign bookwork /mnt/sdcard sudo chroot /mnt/sdcard bash /debootstrap/debootstrap --second-stage exit #Setup network, time and others apt install-y sudo ifupdown net-tools ntpupdate openssh-server udev #Setup password passwd exit #Install Bootloader and Kernel sudo INSTALL_PATH=/mnt/sdcard/boot make install sudo INSTALL_MOD_PATH=/mnt/sdcard make modules_install

Cleanup Image:

#Unmount devices sudo umount /dev/mapper/loop0p1 sudo umount /dev/mapper/loop0p2 sudo kxpart -d /dev/loop0 sudo losetup -d /dev/loop0